#ifndef _Frame_h
#define _Frame_h

#include <opencv\cv.h>
#include <opencv\highgui.h>
#include "opencv2/nonfree/features2d.hpp"

#include "Line.h"
#include "Intersection.h"

class Frame
{
		cv::Mat descriptors;
		std::vector<Line> verticalLines;
		std::vector<Line> horizontalLines;

		std::vector<Line> segmentVerticalLines;
		std::vector<Line> segmentHorizontalLines;
		std::vector<Line> _lines;
		std::vector<Intersection> _intersections;

	public:
		std::vector<cv::KeyPoint> keyPoints;
		cv::Mat _cvOrigFrame;
		cv::Mat _cvFrame;
		cv::Mat _lineMask;
		cv::Mat _scoreMat;
		Frame(cv::Mat);
		Frame();
		~Frame(void);
		std::vector<Line> getHorLines();
		std::vector<Line> getVerLines();
		std::vector<Intersection> getIntSecs();
		//Line (White Pixel) Mask filtering
		void buildLineMask();

		//Line detection and filtering
		void detectLines(std::vector<Line>&);
		void filterLines(std::vector<Line>&);
		void filterLinesVertical();
		void filterLinesHorizontal();
		void detectAndFilterLines(std::vector<Line>&);
		void Frame::resizeLines();
		void Frame::buildScoreMask();
		std::vector<int> findLocalMaximums(cv::Mat, int, double);


		void sortLines();
		bool similarHorizontalLineExist(std::vector<Line>, Line);
		bool similarVerticalLineExist(std::vector<Line>, Line);

		double scoreVerticalLine(Line);
		double scoreHorizontalLine(Line);
		bool goodMatch(int, int);


		//Corner/Line intersection
		void detectIntersections(std::vector<Intersection>&);

		//Bounding box detection
		std::vector<Line> findBoundingLines();
		Line findMinVertLine(std::vector<Line>);
		Line findMaxVertLine(std::vector<Line>);
		Line findMinHorzLine(std::vector<Line>);
		Line findMaxHorzLine(std::vector<Line>);
		void drawFrame(cv::Mat&, bool);

		std::vector<Line> getSegmentHorLines();
		std::vector<Line> getSegmentVerLines();
		
		bool homographyBetweenFrame(cv::Mat, cv::Mat);
};

#endif